﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Entity;

namespace DAL
{
    public class VideoDAL : SqlDataProvider
    {
        #region[Video_GetById]
        public List<Video> Video_GetById(string Id)
        {
            List<Entity.Video> list = new List<Entity.Video>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Video_GetById", GetConnection()))
            {

                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", Id));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(Video.VideoIDataReader(dr));
                    }
                }
                dr.Close();

            }
            return list;
        }
        #endregion
        #region[News_VideoRelated]
        public List<Video> News_VideoRelated(string Id, string GroupVideoId, string lang)
        {
            List<Entity.Video> list = new List<Entity.Video>();
            using (SqlCommand dbCmd = new SqlCommand("sp_News_VideoRelated", GetConnection()))
            {

                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", Id));
                dbCmd.Parameters.Add(new SqlParameter("@GroupVideoId", GroupVideoId));
                dbCmd.Parameters.Add(new SqlParameter("@Lang", lang));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(Video.VideoIDataReader(dr));
                    }
                }
                dr.Close();

            }
            return list;
        }
        #endregion
        #region[Video_GetByOther]
        public List<Video> Video_GetByOther(string Id, string Date, string GroupVideoId, string lang)
        {
            List<Entity.Video> list = new List<Entity.Video>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Video_GetByOther", GetConnection()))
            {

                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", Id));
                dbCmd.Parameters.Add(new SqlParameter("@Date", Date));
                dbCmd.Parameters.Add(new SqlParameter("@GroupVideoId", GroupVideoId));
                dbCmd.Parameters.Add(new SqlParameter("@Lang", lang));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(Video.VideoIDataReader(dr));
                    }
                }
                dr.Close();

            }
            return list;
        }
        #endregion
        #region[Video_GetByTop]
        public List<Video> Video_GetByTop(string Top, string Where, string Order)
        {
            List<Entity.Video> list = new List<Entity.Video>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Video_GetByTop", GetConnection()))
            {

                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Top", Top));
                dbCmd.Parameters.Add(new SqlParameter("@Where", Where));
                dbCmd.Parameters.Add(new SqlParameter("@Order", Order));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(Video.VideoIDataReader(dr));
                    }
                }
                dr.Close();

            }
            return list;
        }
        #endregion
        #region[Video_GetByAll]
        public List<Video> Video_GetByAll(string Lang)
        {
            List<Entity.Video> list = new List<Entity.Video>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Video_GetByAll", GetConnection()))
            {

                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Lang", Lang));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(Video.VideoIDataReader(dr));
                    }
                }
                dr.Close();

            }
            return list;
        }
        #endregion
        #region[Video_Paging]
        public List<Video> Video_Paging(string CurentPage, string PageSize, string Lang)
        {
            List<Entity.Video> list = new List<Entity.Video>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Video_Paging", GetConnection()))
            {

                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@CurentPage", CurentPage));
                dbCmd.Parameters.Add(new SqlParameter("@PageSize", PageSize));
                dbCmd.Parameters.Add(new SqlParameter("@Lang", Lang));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(Video.VideoIDataReader(dr));
                    }
                }
                dr.Close();

            }
            return list;
        }
        #endregion
        #region[Video_Insert]
        public bool Video_Insert(Video data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Video_Insert", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                dbCmd.Parameters.Add(new SqlParameter("@Tag", data.Tag));
                dbCmd.Parameters.Add(new SqlParameter("@Image", data.Image));
                dbCmd.Parameters.Add(new SqlParameter("@File", data.File));
                dbCmd.Parameters.Add(new SqlParameter("@Content", data.Content));
                dbCmd.Parameters.Add(new SqlParameter("@Detail", data.Detail));
                dbCmd.Parameters.Add(new SqlParameter("@Date", data.Date));
                dbCmd.Parameters.Add(new SqlParameter("@Title", data.Title));
                dbCmd.Parameters.Add(new SqlParameter("@Description", data.Description));
                dbCmd.Parameters.Add(new SqlParameter("@Keyword", data.Keyword));
                dbCmd.Parameters.Add(new SqlParameter("@Priority", data.Priority));
                dbCmd.Parameters.Add(new SqlParameter("@Index", data.Index));
                dbCmd.Parameters.Add(new SqlParameter("@Active", data.Active));
                dbCmd.Parameters.Add(new SqlParameter("@GroupVideoId", data.GroupVideoId == "" || data.GroupVideoId == "0" ? DBNull.Value : (object)data.GroupVideoId));
                dbCmd.Parameters.Add(new SqlParameter("@Lang", data.Lang));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Video");
            return true;
        }
        #endregion
        #region[Video_Update]
        public bool Video_Update(Video data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Video_Update", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", data.Id));
                dbCmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                dbCmd.Parameters.Add(new SqlParameter("@Tag", data.Tag));
                dbCmd.Parameters.Add(new SqlParameter("@Image", data.Image));
                dbCmd.Parameters.Add(new SqlParameter("@File", data.File));
                dbCmd.Parameters.Add(new SqlParameter("@Content", data.Content));
                dbCmd.Parameters.Add(new SqlParameter("@Detail", data.Detail));
                dbCmd.Parameters.Add(new SqlParameter("@Date", data.Date));
                dbCmd.Parameters.Add(new SqlParameter("@Title", data.Title));
                dbCmd.Parameters.Add(new SqlParameter("@Description", data.Description));
                dbCmd.Parameters.Add(new SqlParameter("@Keyword", data.Keyword));
                dbCmd.Parameters.Add(new SqlParameter("@Priority", data.Priority));
                dbCmd.Parameters.Add(new SqlParameter("@Index", data.Index));
                dbCmd.Parameters.Add(new SqlParameter("@Active", data.Active));
                dbCmd.Parameters.Add(new SqlParameter("@GroupVideoId", data.GroupVideoId == "" || data.GroupVideoId == "0" ? DBNull.Value : (object)data.GroupVideoId));
                dbCmd.Parameters.Add(new SqlParameter("@Lang", data.Lang));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Video");
            return true;
        }
        #endregion
        #region[Video_Delete]
        public bool Video_Delete(string Id)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Video_Delete", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", Id));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Video");
            return true;
        }
        #endregion

    }
}
